Render Test

Author

someone

Published

February 12, 2024

The goal here is to try to get something, anything, to render with Plotly. So I just stole this code from Stackoverflow and am trying it out. Not really sure what it does.

Unfortunately, not doing anything yet.

This is a total test.

import plotly.express as px
import plotly.io as pio
import IPython

def detect_environment():
    """Detects whether the code is running in Google Colab, Jupyter Notebook, or Quarto."""
    try:
        shell = str(IPython.get_ipython())
        if 'google.colab' in shell:
            return "colab"
        elif 'zmqshell' in shell:
            return "notebook"  # Jupyter Notebook or Quarto
        else:
            return "script"  # Regular Python script
    except NameError:
        return "script"

# Automatically select the correct Plotly renderer
env = detect_environment()  

if env == "colab":
    pio.renderers.default = "colab"
elif env == "notebook":
    pio.renderers.default = "notebook"  # Works for Jupyter Notebook & Quarto
else:
    pio.renderers.default = "browser"  # Opens in web browser for scripts

# Create the plot
fig = px.line(x=[1, 2, 3], y=[1, 2, 3])

# Show the figure
fig.show()